using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region ExchangeRate

	/// <summary>
	/// ExchangeRate object for NHibernate mapped table 'ExchangeRate'.
	/// </summary>
	[Serializable]
	public class ExchangeRate : System.IComparable
		{
		#region Member Variables
		
		protected string _id;
		protected double _exchange;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public ExchangeRate() { }

		public ExchangeRate( double exchange )
		{
			this._exchange = exchange;
		}

		#endregion

		#region Public Properties

		public string Id
		{
			get {return _id;}
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for Id", value, value.ToString());
				_id = value;
			}
		}

		public double Exchange
		{
			get { return _exchange; }
			set { _exchange = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is ExchangeRate))
				throw new InvalidCastException("This object is not of type ExchangeRate");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((ExchangeRate)obj).Id);
					break;
				case "Exchange":
					relativeValue = this.Exchange.CompareTo(((ExchangeRate)obj).Exchange);
					break;
                default:
                    goto case "Id";
			}
            if (ExchangeRate.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
